<?php
/**
 * 
 * @author huangjian E-mail:870596179@qq.com
 * @version 创建时间：2016年10月21日 上午10:42:24 
 * 类说明
 */
class SchoolAction extends BaseAction{

	//列表
	public function getAllData(){
		$Model = M($this->getActionName());
		$map = $this->loadSeachCondition();
		$map['flag'] = 1;
		$total = $Model->where($map)->count();// 查询满足要求的总记录数
		$page = json_decode($this->pageParam($total));
		$data = $Model->where($map)->limit($page->firstRow,$page->listRows)->order($page->sort)->select();
		$vo = $this->toJosnForGird($data,$page);
		echo json_encode($vo);
	}

	public function schoolAreaList(){
		$SareasModel = M('SchoolAreas');
		$SchoolModel = M('School');
		$ShopModel = M('Shop');
		$map['school_id'] = $_REQUEST['id'];
		$map['flag'] = 1;
		$total = $SareasModel->where($map)->count();// 查询满足要求的总记录数
		$page = json_decode($this->pageParam($total));
		$data = $SareasModel->where($map)->limit($page->firstRow,$page->listRows)->order($page->sort)->select();
		$School = $SchoolModel->where(array('id'=>$map['school_id']))->field("name")->find();
		for($i=0;$i<count($data);$i++){
			$shopCount = $ShopModel->where("school_area_id=".$data[$i]['id'])->count();
			if($shopCount){
				$data[$i]['shopCount'] = $shopCount;
			}else{
				$data[$i]['shopCount'] = "无";
			}
			$data[$i]['school'] = $School['name'];
		}
		$vo = $this->toJosnForGird($data,$page);
		echo json_encode($vo);
	}

	/*
	 * 学校大楼列表
	 */
	public function schoolFloorList(){
		$SchoolFloorModel = M('SchoolFloor');
		$SchoolModel = M('School');
		$map['school_id'] = $_REQUEST['id'];
		$map['flag'] = 1;
		$total = $SchoolFloorModel->where($map)->count();// 查询满足要求的总记录数
		$page = json_decode($this->pageParam($total));
		$data = $SchoolFloorModel->where($map)->limit($page->firstRow,$page->listRows)->order($page->sort)->select();
		$School = $SchoolModel->where(array('id'=>$map['school_id']))->field("name")->find();
		for($i=0;$i<count($data);$i++){
			$data[$i]['school'] = $School['name'];
		}
		$vo = $this->toJosnForGird($data,$page);
		echo json_encode($vo);
	}
}